window.onload = totalPrice;

//减
function  minus(n){
    var names = document.querySelectorAll("[name=amount]");
    if(parseInt(names[n].value)>1){
        names[n].value = parseInt(names[n].value)-1;
    }

    var prices = document.querySelectorAll("[name=price]");
    var total = prices[n].value * names[n].value;
    var price0 = document.querySelector("#price"+n);
    price0.innerHTML = "￥"+total;
    totalPrice();
}

//加
function plus(n){
    var names = document.querySelectorAll("[name=amount]");
    names[n].value = parseInt(names[n].value)+1;

    var prices = document.querySelectorAll("[name=price]");
    var total = prices[n].value * names[n].value;
    var price0 = document.querySelector("#price"+n);
    price0.innerHTML = "￥"+total;
    totalPrice();

}
function totalPrice(){
    var total = 0;
    //购买数量
    var names = document.querySelectorAll("[name=amount]");
    //购买价格
    var prices = document.querySelectorAll("[name=price]");
    for(var i = 0 ; i < names.length ;i++){
        total += prices[i].value * names[i].value;
    }
    document.querySelector("#totalPrice").innerHTML = "￥"+total;
}